package com.itheima.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;

/**
 * @Author: yangshuai
 * @Desc: 瑞吉-自动填充处理器
 * @Date: 2022-06-6 10:23:18
 */
@Component
@Slf4j
public class ReggieMetaObjectHandler implements MetaObjectHandler {
	/**
	 * 功能描述: 新增时执行自动填充功能
	 * @param metaObject
	 * @return : void
	 */
	@Override
	public void insertFill(MetaObject metaObject) {
		Long currentId = BaseContext.getCurrentId();
		log.info("ReggieMetaObjectHandler.insertFill当前线程的ID为：-------"+Thread.currentThread().getId()+"-----------"+currentId);
		log.info("公共字段自动填充[insert]...");
		metaObject.setValue("createTime", LocalDateTime.now());
		metaObject.setValue("updateTime",LocalDateTime.now());
		metaObject.setValue("createUser",currentId);
		metaObject.setValue("updateUser",currentId);
	}
	/**
	 * 功能描述: 修改时执行自动填充功能
	 * @param metaObject
	 * @return : void
	 */
	@Override
	public void updateFill(MetaObject metaObject) {
		Long currentId = BaseContext.getCurrentId();
		log.info("ReggieMetaObjectHandler.updateFill当前线程的ID为：-------"+Thread.currentThread().getId()+"-----------"+currentId);
		log.info("公共字段自动填充[insert]...");
		metaObject.setValue("updateTime",LocalDateTime.now());
		metaObject.setValue("updateUser",currentId);
	}
}
